package com.zfl.practice;

import lombok.Data;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

@Data
public class GiveLike {
    private int like;

    public synchronized void giveLike(){
        this.like++;
    }

    private AtomicLong atomicLike = new AtomicLong(0);

    public void giveLikeByAtomicLong() {
        this.atomicLike.incrementAndGet();
    }

    private LongAdder adderLike = new LongAdder();

    public void giveLikeByLongAdder() {
        this.adderLike.increment();
    }

    private LongAccumulator accumulatorLike = new LongAccumulator(Long::sum,0);

    public void giveLikeByAccumulator() {
        accumulatorLike.accumulate(1);
    }

}
